home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d1 / marxmenu.arc / ENV.MNU < prev    next >
Text File  |  1991-03-27  |  6KB  |  288 lines

  1. Comment
  2. =============================================================
  3.  
  4. Environment Editor * Copyright 1990 by Marc Perkel
  5.  
  6. This is a MarxMenu demo program that lets you edit your master
  7. environment area. To use type: MARXMENU ENV
  8.  
  9. =============================================================
  10. EndComment
  11.  
  12. Var
  13.   Env, Env2, Paths, Paths2, NewPath, SetString, SetA, SetB, Middle
  14.   PathLevel
  15.  
  16. Const MyEditor = 'ME.EXE'
  17.  
  18. ClearScreenOnExit Off
  19.  
  20. MasterEnvironment
  21. ReadEnvironment(Env)
  22.  
  23. UseArrows
  24. BoxBorderColor Green Blue
  25. BoxInsideColor Yellow Blue
  26. if ColorScreen
  27.    BoxHeaderColor Yellow Mag
  28.    InverseColor Yellow Red
  29. else
  30.    BoxHeaderColor Black Grey
  31.    InverseColor Black Grey
  32. endif
  33. BoxHeader ' Environment '
  34. DrawBox 27 6 32 9
  35. TextColor LCyan Blue
  36. ClearLine 205
  37. TextColor Yellow Blue
  38. Writeln
  39. Writeln '   A - Change One Line'
  40. Writeln '   B - Delete Lines'
  41. Writeln '   C - Edit Environment'
  42. Writeln '   D - Sort Environment'
  43. Writeln '   E - Edit Paths'
  44. Write   '   F - Information'
  45.  
  46. OnKey 'A'
  47.    ^SetALine
  48.  
  49. OnKey 'B'
  50.    ^DelLines
  51.  
  52. OnKey 'C'
  53.    ^EdEnv
  54.  
  55. OnKey 'D'
  56.    |DrawBox 33 13 11 3
  57.    |Write ' Sorting'
  58.    |Sort(1,NumberOfElements(Env))
  59.    |WasteEnv(Env)
  60.    |WriteEnv(Env)
  61.    |Wait 20
  62.    |EraseTopWindow
  63.  
  64. OnKey 'E'
  65.    ^EdPath
  66.  
  67. OnKey 'F'
  68.    |BoxHeader ' Information '
  69.    |DrawBox 30 9 32 6
  70.    |TextColor LCyan Blue
  71.    |ClearLine 205
  72.    |TextColor Yellow Blue
  73.    |Writeln
  74.    |Writeln '    Environment Size: ' EnvSize
  75.    |Writeln '    Environment Free: ' EnvFree
  76.    |Write   '    Environment Used: ' (EnvSize - EnvFree)
  77.    |WaitOrKBDReady 4000
  78.    |EraseTopWindow
  79.  
  80. :SetALine
  81. if NumberOfElements(Env) > 1
  82.    BoxHeader ' Pick String to Edit '
  83.    DrawPickBox(Env)
  84.    SetString = PickOne Env
  85.    EraseTopWindow
  86.    EraseTopWindow
  87. endif
  88. if NumberOfElements(Env) = 1 then SetString = Env[1]
  89. if LastKey = Esc then ExitMenu
  90. SetA = Left(SetString,pos('=',SetString) - 1)
  91. delete(SetString,1,pos('=',SetString))
  92. DrawBox 1 20 80 3
  93. Write ' ' SetA '='
  94. InputString = SetString
  95. SetB = Readln
  96. EraseTopWindow
  97. if LastKey = Esc then ExitMenu
  98. SetEnv(SetA + '=' + SetB)
  99. ExitMenu
  100.  
  101. :DelLines
  102. BoxHeader ' Mark Lines to Delete '
  103. DrawPickBox(Env)
  104. PickMany(Env,Env2)
  105. EraseTopWindow
  106. EraseTopWindow
  107. WasteEnv(Env2)
  108. ExitMenu
  109.  
  110. :EdEnv
  111. WriteTextFile ('ENV.TMP',Env)
  112. Explode Off
  113. Execute (MyEditor + ' ENV.TMP')
  114. ReadTextFile ('ENV.TMP',Env2)
  115. DelFile ('ENV.TMP')
  116. DelFile ('ENV.BAK')
  117. WasteEnv(Env)
  118. WriteEnv(Env2)
  119. ExitMenu
  120.  
  121. :EdPath
  122. SeparatePaths
  123. BoxHeader ' Edit Path '
  124. DrawBox 30 9 32 5
  125. TextColor LCyan Blue
  126. ClearLine 205
  127. TextColor Yellow Blue
  128. Writeln
  129. Writeln '   A - Add a Path'
  130. Write   '   B - Delete Paths'
  131.  
  132. OnKey 'A'
  133.    |DrawBox 1 20 80 3
  134.    |repeat
  135.    |   Write ' New Path: '
  136.    |   NewPath = UpperCase(Readln)
  137.    |until ExistDir(NewPath) or (LastKey = Esc) or (SetB = '')
  138.    |EraseTopWindow
  139.    |if ExistDir(NewPath) and (LastKey <> Esc)
  140.    |   Paths[NumberOfElements(Paths) + 1] = NewPath
  141.    |endif
  142.    |MergePaths
  143.  
  144. OnKey 'B'
  145.    ^DelPaths
  146.  
  147. :DelPaths
  148. BoxHeader ' Mark Paths to Delete '
  149. PathLevel = True
  150. DrawPickBox(Paths)
  151. PathLevel = False
  152. PickMany(Paths,Paths2)
  153. EraseTopWindow
  154. EraseTopWindow
  155. EraseTopWindow
  156. EraseTopWindow
  157. SubtractPaths(Paths,Paths2)
  158. MergePaths
  159. ExitMenu
  160.  
  161. ;------ Recursive Quicksort
  162.  
  163. Procedure Sort (L,R)
  164. var I,J
  165.    I = L
  166.    J = R
  167.    Middle = Env[(L+R)/2]
  168.    repeat
  169.       while Env[I] < Middle
  170.          I = I + 1
  171.       endwhile
  172.       while Middle < Env[J]
  173.          J = J - 1
  174.       endwhile
  175.       if I <= J
  176.          Middle = Env[J]
  177.          Env[J] = Env[I]
  178.          Env[I] = Middle
  179.          I = I + 1
  180.          J = J - 1
  181.       endif
  182.    until I > J
  183.    if (J - L) < (R - I)
  184.       if L < J then Sort(L,J);
  185.       if I < R then Sort(I,R);
  186.    else
  187.       if I < R then Sort(I,R);
  188.       if L < J then Sort(L,J);
  189.    endif
  190. EndProc
  191.  
  192.  
  193. Procedure WasteEnv (EnvArray)
  194.    Loop NumberOfElements(EnvArray)
  195.       EnvArray[LoopIndex] = Left(EnvArray[LoopIndex],pos('=',EnvArray[LoopIndex]))
  196.       SetEnv(EnvArray[LoopIndex])
  197.    EndLoop
  198. EndProc
  199.  
  200.  
  201. Procedure WriteEnv (EnvArray)
  202.    Loop NumberOfElements(EnvArray)
  203.       SetEnv(EnvArray[LoopIndex])
  204.    EndLoop
  205. EndProc
  206.  
  207.  
  208. Procedure DrawPickBox (ChooseList)
  209. var BoxDim Longest
  210.    Longest = length(BoxHeader) - 2
  211.    Loop NumberOfElements(ChooseList)
  212.       Longest = Max(Longest,length(ChooseList[LoopIndex]))
  213.    EndLoop
  214.    BoxDim[3] = Min(Longest + 6,ScreenWidth - 6)
  215.    BoxDim[4] = Min(NumberOfElements(ChooseList) + 3,ScreenHeight)
  216.    if PathLevel
  217.       BoxDim[1] = Max(Min(33,ScreenWidth - BoxDim[3]),1)
  218.       BoxDim[2] = Max(Min(12,ScreenHeight - BoxDim[4]),1)
  219.    else
  220.       BoxDim[1] = Max(Min(30,ScreenWidth - BoxDim[3]),1)
  221.       BoxDim[2] = Max(Min(9,ScreenHeight - BoxDim[4]),1)
  222.    endif
  223.    DrawBox BoxDim[1] BoxDim[2] BoxDim[3] BoxDim[4]
  224.    TextColor LCyan Blue
  225.    ClearLine 205
  226.    TextColor Yellow Blue
  227.    NoBoxBorder
  228.    Explode Off
  229.    DrawBox BoxDim[1] + 1 BoxDim[2] + 2 BoxDim[3] - 2 BoxDim[4] - 3
  230.    BlockBox
  231.    Explode
  232. EndProc
  233.  
  234.  
  235. Procedure AppendPaths (Directory)
  236.    if ExistDir(Directory)
  237.       Paths[NumberOfElements(Paths) + 1] = Directory
  238.    endif
  239. EndProc
  240.  
  241.  
  242. Procedure SeparatePaths
  243. var Path B
  244.    Path = UpperCase(ReadEnv('PATH'))
  245.    Dispose(Paths)
  246.    while Path > ''
  247.       B = pos(';',Path)
  248.       if B > 0
  249.          AppendPaths(Left(Path,B - 1))
  250.          delete(Path,1,B)
  251.       else
  252.          AppendPaths(Path)
  253.          Return
  254.       endif
  255.    endwhile
  256. EndProc
  257.  
  258.  
  259. Procedure MergePaths
  260. var Path
  261.    Path = ''
  262.    Loop NumberOfElements(Paths)
  263.       Path = Path + Paths[LoopIndex] + ';'
  264.    EndLoop
  265.    SetEnv('PATH=' + Path)
  266. EndProc
  267.  
  268.  
  269. Procedure SubtractPaths (Org,Sub)
  270. var I Match
  271.    Dispose(Paths)
  272.    I = 1
  273.    while I <= NumberOfElements(Org)
  274.       Match = False
  275.       Loop NumberOfElements(Sub)
  276.          if Org[I] = Sub[LoopIndex]
  277.             Match = True
  278.          endif
  279.       EndLoop
  280.       if not Match then Paths[NumberOfElements(Paths) + 1] = Org[I]
  281.       I = I + 1
  282.    endwhile
  283. EndProc
  284.  
  285. ;loop numberofelements(Paths)
  286. ;   writeln Paths[loopindex]
  287. ;endloop
  288.